package com.atguigu.flink.chapter11;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/10/20 15:17
 */
public class Flink06_SQL_File {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
        
        // 通过ddl建立一个动态表, 与file source进行关联
        tenv.executeSql("create table sensor(id string, ts bigint, vc int" +
                            ")with(" +
                            "   'connector' = 'filesystem', " +
                            "   'path' = 'input/sensor.txt', " +
                            "   'format' = 'csv' " +
                            ")");
    
        //建立动态表与sink 进行关联
        tenv.executeSql("create table b(id string, vc int" +
                            ")with(" +
                            "   'connector' = 'filesystem', " +
                            "   'path' = 'input/b.txt', " +
                            "   'format' = 'csv' " +
                            ")");
    
//        Table result = tenv.sqlQuery("select id, vc from sensor where id='sensor_1'");
//        result.executeInsert("b");
    
        tenv.executeSql("insert into  b select id, vc from sensor where id='sensor_1' ");
        
    }
}
